package utils

import (
	"crypto/md5"
	"encoding/hex"
	"io"
	"os"
)

// GetFileMd5 计算文件md5
func GetFileMd5(filePath string) (md5Str string, err error) {
	var file *os.File
	if file, err = os.OpenFile(filePath, os.O_RDONLY, os.ModePerm); err != nil {
		return "", err
	}
	defer file.Close()
	md := md5.New()
	if _, err = io.Copy(md, file); err != nil {
		return "", err
	}
	return hex.EncodeToString(md.Sum(nil)), nil
}
